/**   
 * @Title: BeidanHistoryLotteryInfoCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.lotteryinfo 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2012-1-10 下午4:28:01  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.lotteryinfo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.FootballLotteryInfoListInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: BeidanHistoryLotteryInfoCommunicater
 * @Description: (北京单场历史开奖信息通讯接口)
 * @author: Billy Qigs@500wan.com
 * @date: 2012-1-10 下午4:28:01
 * 
 */
public class BeidanHistoryLotteryInfoCommunicater extends ServerCommunicater {

	public boolean isGetLotteryInfoSucceed(String expect) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(Config.PASER_MID, BussinessCode.MID_BEIDAN_HISTORY_LOTTERY_INFO));
		list.add(mapItem(Config.PASER_CK, Config.NULLMARK));
		list.add(mapItem(Key.KEY_EXPECT, expect));

		super.getServerResponse(list, true);
		if (super.getState() == 100) {
			isSucceed = true;
			if (super.getListResult().size() == 0) {
				EDebug.o("list 为空");
				isSucceed = false;
			} else {
				EDebug.o("list 不为空");
			}
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}

	public ArrayList<FootballLotteryInfoListInfo> getBeidanLotteryInfo() {

		ArrayList<FootballLotteryInfoListInfo> returnList = new ArrayList<FootballLotteryInfoListInfo>();

		int count = super.getListResult().size();
		for (int i = 0; i < count; i++) {
			FootballLotteryInfoListInfo lotteryInfo = new FootballLotteryInfoListInfo();
			if (super.getListResult().get(i).get(Key.KEY_RESULTSPF).equals(Language.STR_WIN)) {
				lotteryInfo.setState(Config.NUM2);
			} else if (super.getListResult().get(i).get(Key.KEY_RESULTSPF).equals(Language.STR_DRAW)) {
				lotteryInfo.setState(Config.NUM1);
			} else if (super.getListResult().get(i).get(Key.KEY_RESULTSPF).equals(Language.STR_LOST)) {
				lotteryInfo.setState(Config.NUM0);
			} else {
				continue;
			}
			lotteryInfo.setMatchNumDate(super.getListResult().get(i).get(Key.KEY_SCHEDULESDATE));
			lotteryInfo.setDayOfWeek(super.getListResult().get(i).get(Key.KEY_MATCHWEEK));
			lotteryInfo.setHomeTeam(super.getListResult().get(i).get(Key.KEY_HOMESXNAME));
			lotteryInfo.setRangQiu(super.getListResult().get(i).get(Key.KEY_RANGQIU));
			lotteryInfo.setScore(super.getListResult().get(i).get(Key.KEY_MATCHSCORE));
			lotteryInfo.setVisitingTeam(super.getListResult().get(i).get(Key.KEY_GUESTSXNAME));
			lotteryInfo.setSimpleLeague(super.getListResult().get(i).get(Key.KEY_LEAGUEMATCHNAME));
			lotteryInfo.setMatchNum(super.getListResult().get(i).get(Key.KEY_ORDERNUM));
			lotteryInfo.setHomeTeamImage(super.getListResult().get(i).get(Key.KEY_HOMESXNAMEID));
			lotteryInfo.setVisitTeamImage(super.getListResult().get(i).get(Key.KEY_AWAYSXNAMEID));

			returnList.add(lotteryInfo);
		}
		return returnList;

	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
